package com.mdd.common.mapper.orders;

import com.mdd.common.core.basics.IBaseMapper;
import com.mdd.common.entity.orders.OrdersDish;
import com.mdd.common.entity.orders.OrdersDishListVo;
import org.apache.ibatis.annotations.*;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrdersDishMapper extends IBaseMapper<OrdersDish> {
    @Update("update la_orders_dish set quantity = quantity + 1 ,order_flag='1' where id = #{id}")
    void dishInc(Integer id);

    @Update("update la_orders_dish set quantity = quantity - 1,order_flag='1' where id = #{id}")
    void dishDec(Integer id);

    @Update("update la_orders_dish set order_flag='2' where order_id = #{id}")
    void updateOrderFlag(Integer id);

    @Delete("delete from la_orders_dish where id = #{id}")
    void dishDel(Integer id);

    List<OrdersDishListVo> getorderList(@Param("id") Integer id,@Param("flag")String flag);

    @Select("select id AS id,dish_Id as dishId  FROM la_orders_dish WHERE order_id = #{id} AND order_flag = 1 ")
    List<OrdersDishListVo>  getEmptyInfoByOrderId(Integer id);

    @Select("select sum(quantity*amount) from la_orders_dish where order_id = #{id}")
    BigDecimal compute(Integer id);

    @Select("select order_id as orderId,dish_id as dishId  from la_orders_dish where id=#{id}")
    OrdersDish getDishAndOrderInfo(Integer id);

    @Select("select  id,dish_id as dishId ,order_id as orderId,quantity,amount from la_orders_dish where order_id =#{orderId} and dish_id = #{dishId} ORDER BY create_time desc")
    List<OrdersDish> getDishAndOrderListInfo(@Param("orderId") Integer orderId,@Param("dishId") Integer dishId);

    @Select("select id,user_num as userNum from la_orders a where a.desk_id =#{diskId} ORDER BY checkout_time desc LIMIT 1")
    Map<String,String> getUpOrderByDiskId(Integer diskId);
    @Select("select id from la_orders_dish l where l.order_id=#{orderId} and dish_id =#{dishId} and l.order_flag = 1")
    Integer getNoCommitOrder(@Param("orderId") Integer orderId,@Param("dishId") Integer dishId);

    Map<String, String> getOrderStatistics(@Param("aid")Integer aid,@Param("currentAidChindId")List<Integer> currentAidChindId, @Param("beginTime")Long aLong, @Param("endTime")Long aLong1);

    List<Map<String, Object>> getOrderStatisticsByDate(@Param("aid")Integer adminId,@Param("currentAidChindId") List<Integer> currentAidChindId,@Param("datestrings") List<String> datestrings);

    List<Map<String, Object>> getUpDishInfo(@Param("aid")Integer adminId,@Param("currentAidChindId") List<Integer> currentAidChindId,@Param("beginTime")Long aLong, @Param("endTime")Long aLong1);
}
